/**
 * Free Uch Pm Check Simulation Comet Js
 *
 * @category   FreeUch
 * @copyright  Copyright 2009 lordharrdlee(http://www.lordharrdlee.cn)
 * @author     lordharrdlee<lordharrdlee@gmail.com>
 * @version    $Id: pmcomet.js 4 2010-01-13 06:51:42Z lordharrdlee $
 */
function Comet() {

	this.timestamp = 0;
	this.url = './freeuch/pmcomet.php';
	this.noerror = true;

	this.connect = function() {

		this.ajax = jQuery.ajax( {
			type : 'GET',
			url : Comet.url,
			data : 'timestamp=' + Comet.timestamp + '&' + Math.random(),
			success : function(transport) {
				var response = eval('(' + transport + ')');
				Comet.timestamp = response.timestamp;
				Comet.handleResponse(response);
				Comet.noerror = true;
			},
			complete : function(transport) {
				if (!Comet.noerror) {
					setTimeout(function() {
						comet.connect()
					}, 5000);
				} else {
					Comet.connect();
				}
				Comet.noerror = false;
			}
		});
	}

	this.handleResponse = function(response) {
		var membernotemenu_html = '';
		var numall = 0;
		if (response.msg.notenum > 0) {
			membernotemenu_html += '<li><img src="image/icon/notice.gif" width="16" alt="" /> <a href="space.php?do=notice"><strong>'+response.msg.notenum+'</strong> 个新通知</a></li>';
			numall += parseInt(response.msg.notenum);
		}
		if (response.msg.pokenum > 0) {
			membernotemenu_html += '<li><img src="image/icon/poke.gif" alt="" /> <a href="cp.php?ac=poke"><strong>'+response.msg.pokenum+'</strong> 个新招呼</a></li>';
			numall += parseInt(response.msg.pokenum);
		}
		if (response.msg.addfriendnum > 0) {
			membernotemenu_html += '<li><img src="image/icon/friend.gif" alt="" /> <a href="cp.php?ac=friend&op=request"><strong>'+response.msg.addfriendnum+'</strong> 个好友请求</a></li>';
			numall += parseInt(response.msg.addfriendnum);
		}
		if (response.msg.mtaginvitenum > 0) {
			membernotemenu_html += '<li><img src="image/icon/mtag.gif" alt="" /> <a href="cp.php?ac=mtag&op=mtaginvite"><strong>'+response.msg.mtaginvitenum+'</strong> 个群组邀请</a></li>';
			numall += parseInt(response.msg.mtaginvitenum);
		}
		if (response.msg.eventinvitenum > 0) {
			membernotemenu_html += '<li><img src="image/icon/event.gif" alt="" /> <a href="cp.php?ac=event&op=eventinvite"><strong>'+response.msg.eventinvitenum+'</strong> 个活动邀请</a></li>';
			numall += parseInt(response.msg.eventinvitenum);
		}
		if (response.msg.myinvitenum > 0) {
			membernotemenu_html += '<li><img src="image/icon/userapp.gif" alt="" /> <a href="space.php?do=notice&view=userapp"><strong>'+response.msg.myinvitenum+'</strong> 个应用消息</a></li>';
			numall += parseInt(response.msg.myinvitenum);
		}
		if (membernotemenu_html) {
			jq('#membernotemenu').html('<a href="space.php?do=notice">'+numall+'个提醒</a>');
			jq('#membernotemenu').show();
			jq('#membernotemenu_menu').html(membernotemenu_html);
		}
	}

}
var Comet = new Comet();
setTimeout(function() {
	Comet.connect();
}, 15000);